<?php
/**
 * Created by IntelliJ IDEA.
 * User: Fernando
 * Date: 22/10/2014
 * Time: 08:37
 */

namespace Fiestissima\CRM\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityRepository;

class OrdenCompraPagoType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('orden_compra_pago_id', 'text')
            ->add('ordenCompra', 'entity', array('class' => 'FiestissimaCRM:OrdenCompra',
                'query_builder' => function(EntityRepository $er) {
                        return $er->createQueryBuilder('op')
                            ->orderBy('op.orden_compra_fecha', 'ASC');
                    }, 'expanded' => false, 'multiple' => false))
            ->add('formaPago', 'entity', array('class' => 'FiestissimaCRM:FormaPago',
                'query_builder' => function(EntityRepository $er) {
                        return $er->createQueryBuilder('fp')
                            ->orderBy('fp.forma_pago_nombre', 'ASC');
                    }, 'expanded' => false, 'multiple' => false))
            ->add('orden_compra_pago_subtotal', 'text');
    }

    public function getName()
    {
        return 'ordenCompraPago';
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Fiestissima\CRM\Entity\OrdenCompraPago',
        ));
    }
} 